package s12;

import net.sf.cglib.proxy.Mixin;

/**
 * Mixin能够让我们将多个对象整合到一个对象中去，前提是这些对象必须是接口的实现。
 *
 * @author wangpp
 */
public class MixinTest {
    interface Interface1 {
        String first();
    }

    interface Interface2 {
        String second();
    }

    interface MixinInterface extends Interface1, Interface2 {
    }

    static class Class1 implements Interface1 {
        @Override
        public String first() {
            return "first";
        }
    }

    static class Class2 implements Interface2 {
        @Override
        public String second() {
            return "second";
        }
    }

    public static void main(String[] args) {
        Mixin mixin = Mixin.create(new Class[]{Interface1.class, Interface2.class, MixinInterface.class},
                new Object[]{new Class1(), new Class2()}
        );
        MixinInterface m = (MixinInterface) mixin;
        System.out.println(m.first());
        System.out.println(m.second());
    }
}
